from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey, Date, Numeric
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relation, backref

Base = declarative_base()

class Account(Base):
    __tablename__ = 'Accounts'

    id = Column(Integer, primary_key=True)
    nr_rachunku = Column(String, nullable=False, unique=True)
    waluta = Column(String, nullable=False)
    rodzaj_rachunku = Column(String, nullable=False)

    transactions = relation("Transaction")

    def __repr__(self):
       return "Account: %s, %s, %s" % (self.id, self.nr_rachunku, self.rodzaj_rachunku)

class Message(Base):
    __tablename__ = 'Messages'

    id = Column(Integer, primary_key=True)
    date = Column(Date, nullable=False, unique=True)
    subject = Column(String, nullable=False)

    def __repr__(self):
       return "Message: %s, %s, %s" % (self.id, self.Date, self.Subject)

class Transaction(Base):
    __tablename__ = 'Transactions'

    id = Column(Integer, primary_key=True)
    accountId = Column(Integer, ForeignKey('Accounts.id'))
    messageId = Column(Integer, ForeignKey('Messages.id'))
    data_operacji = Column(Date, nullable=False)
    data_ksiegowania = Column(Date)
    opis_operacji = Column(String)
    nazwa = Column(String)
    rachunek = Column(String)
    nazwa_banku = Column(String)
    opis_dodatkowy = Column(String)    
    kwota = Column(Numeric, nullable=False)
    saldo_po_operacji = Column(Numeric, nullable=False)

    account = relation("Account")

    def __repr__(self):
       return "Transaction: %s, %s, %s" % (self.id, self.data_operacji, self.kwota)
